<?php
session_name("interoprouter");
session_start();

/*
 * CONFIGURACAO OBRIGATORIAS
 * variaveis de configuracao obrigatorias para funcionamento do site
 */
$name = "conta";	// nome da pagina atual
$_SESSION["page"] = "conta.php";
if ( isset( $_SESSION["lang"] ) == false ) $_SESSION["lang"] = "br";
$lang = $_SESSION["lang"];


/*
 * CONFIGURACAO 
 * variaveis de configuracao
 */
$gatelevel = "account";
$title = "Website";

/*
 * CABECALHO DA PAGINA
 * includes e inicio da construcao do layout
 */
ob_start(); include("modules/session.php"); ob_end_clean();
ob_start(); include("modules/database.php"); ob_end_clean();
include("template/templateBodyGen.php");

$javascripts = array();
makeHeader($title, $javascripts);

/*
 * CONTROLES DO CASO DE USO
 * funcoes que o caso de uso vai executar
 */
//$exemplo = array("dado 1", "dado 2", "dado 3", "dado 4");

	$accountId = $_SESSION["accountId"];
	$dbSql = "SELECT * FROM accounts WHERE accountId=$accountId LIMIT 1";
	$dbResult = @mysql_query($dbSql);
	if ($dbResult == false)
		$flagDB = false;
	else
	{
		$flagDB = true;
		
		$dbRow = @mysql_fetch_assoc($dbResult);
		$userdata = array
					(
						"username" => $dbRow["accountUser"],
						"owner" => $dbRow["accountOwner"],
						"email" => $dbRow["accountEmail"],
						"company" => $dbRow["accountOrganization"],
						"phone" => $dbRow["accountTelephone"]
					);
		@mysql_free_result($dbResult);

		$dbSql = "SELECT COUNT(*) as total FROM projects WHERE accountId=$accountId";
		$dbResult = @mysql_query($dbSql);
		$dbRow = @mysql_fetch_assoc($dbResult);
		$projectdata = $dbRow["total"];
		@mysql_free_result($dbResult);

		$dbSql = "SELECT COUNT(*) as total FROM jobs WHERE projectId IN ( SELECT projectId FROM projects WHERE accountId=$accountId )";
		$dbResult = @mysql_query($dbSql);
		$dbRow = @mysql_fetch_assoc($dbResult);
		$jobdata = $dbRow["total"];
		@mysql_free_result($dbResult);

		$data = array_merge( $userdata, array("projects" => $projectdata), array("jobs" => $jobdata) );

	}

/*
 * RENDERIZA PAGINA
 * aqui vao os includes e as variaveis de configuracao
 */
// $flagDB # database on or off
// $data # all data about user
include("lang/{$lang}/{$name}.php");



/*
 * RODAPE DA PAGINA
 * encerra a pagina coma as tags necessarias
 */
makeFooter();

?>